<?php
class page
{
	/**
	 * 处理分页，返回的是字符串。
	 * @param int $count 该数据总数
	 * @param int $curpage 当前page
	 * @param int $pagesize	每页大小
	 * @param string $jumpUrl 跳转地址
	 * @param int $type 样式类型 默认为0，系统样式
	 */
	function getMulti($count,$curpage,$pagesize,$jumpUrl,$type=0)
	{
		$str="setmulti$type";
		$mutitl=self::$str($count,$curpage,$pagesize,$jumpUrl);
		return $mutitl;
	}
	/**
	 *
	 * 去除url中指定的参数
	 * @param string $url
	 * @param string|array $params
	 * */
	function getUrlPage($url,$params='page'){
		return preg_replace(array('/([&\?])('.(is_array($params)?implode('|',$params):$params).')?=[^&]*/e', '/\?&+/'),array("'\\1'=='?'?'?':''",'?'), $url);
	}
	//系统样式
	private function setmulti0($num,$curpage,$perpage,$jumpUrl)
	{
		$maxpage=ceil($num/$perpage);//Custom 最大页码自定义
		$minpage=1;//Custom
		$mpurl=$jumpUrl;
		global $_SCONFIG, $_SGLOBAL;

		if(empty($ajaxdiv) && $_SGLOBAL['inajax']) {
			$ajaxdiv = $_GET['ajaxdiv'];
		}
		$page = 10;
		//$maxpages=ceil($num/$perpage);
		if($maxpages) $page =12;//有待改善

		$multipage = '';
		$mpurl .= strpos($mpurl, '?') ? '&' : '?';
		$realpages = 1;
		if($num > $perpage) {
			$offset = 2;
			$realpages = @ceil($num / $perpage);
			$pages = $maxpage && $maxpage < $realpages ? $maxpage : $realpages;
		if($page > $pages) {
			$from = 1;
			$to = $pages;
		} else {
			$from = $curpage - $offset;
			$to = $from + $page - 1;
			if($from < 1) {
				$to = $curpage + 1 - $from;
				$from = 1;
				if($to - $from < $page) {
					$to = $page;
				}
			} elseif($to > $pages) {
				$from = $pages - $page + 1;
				$to = $pages;
			}
		}
		$multipage = '';
		$urlplus = $todiv?"#$todiv":'';
		if($curpage - $offset > 1 && $pages > $page) {
			$multipage .= "<a class=\"num\" ";
			if($_SGLOBAL['inajax']) {
				$multipage .= "href=\"javascript:;\" onclick=\"ajaxget('{$mpurl}page=1&ajaxdiv=$ajaxdiv', '$ajaxdiv')\"";
			} else {
				$multipage .= "href=\"{$mpurl}page=1{$urlplus}\"";
			}
			$multipage .= ' class="first">1 ...</a>';
		}
		if($curpage > 1) {
			$multipage .= "<a class=\"num\"  ";
			if($_SGLOBAL['inajax']) {
				$multipage .= "href=\"javascript:;\" onclick=\"ajaxget('{$mpurl}page=".($curpage-1)."&ajaxdiv=$ajaxdiv', '$ajaxdiv')\"";
			} else {
				$multipage .= "href=\"{$mpurl}page=".($curpage-1)."$urlplus\"";
			}
			$multipage .= " class=\"prev\">上一页</a>";
		}
		for($i = $from; $i <= $to; $i++) {
			if($i == $curpage) {
				$multipage .= '<a  class="num current " >'.$i.'</a>';
			} else {
				$multipage .= "<a  class=\"num\" ";
				if($_SGLOBAL['inajax']) {
					$multipage .= "href=\"javascript:;\" onclick=\"ajaxget('{$mpurl}page=$i&ajaxdiv=$ajaxdiv', '$ajaxdiv')\"";
				} else {
					$multipage .= "href=\"{$mpurl}page=$i{$urlplus}\"";
				}
				$multipage .= ">$i</a>";
			}
		}
		if($curpage < $pages) {
			$multipage .= "<a  class=\"num\" ";
			if($_SGLOBAL['inajax']) {
				} else {
				$multipage .= "href=\"{$mpurl}page=".($curpage+1)."{$urlplus}\"";
			}
			$multipage .= " class=\"next\">下一页</a>";
		}
		if($to < $pages) {
			$multipage .= "<a  class=\"num\" ";
			if($_SGLOBAL['inajax']) {
				$multipage .= "href=\"javascript:;\" onclick=\"ajaxget('{$mpurl}page=$pages&ajaxdiv=$ajaxdiv', '$ajaxdiv')\"";
			} else {
				$multipage .= "href=\"{$mpurl}page=$pages{$urlplus}\"";
			}
			$multipage .= " class=\"last\">... $realpages</a>";
		}

	}
	return $multipage;

	}
	//自定义样式
	private function setmulti1($count,$curpage,$pagesize,$jumpUrl)
	{
		return 'hello,1';
	}
//自定义样式
	private function setmulti2($count,$curpage,$pagesize,$jumpUrl)
	{
		return 'hello,2';
	}//自定义样式
	private function setmulti3($count,$curpage,$pagesize,$jumpUrl)
	{
		return 'hello,3';
	}
}